<template>
    <div>
        <!-- 关键词搜索栏 -->
        <div>
            <div class="flex">
                <div class="">
                    <!-- 暂时屏蔽新建订单 -->
                    <!-- <el-button type="primary" icon="el-icon-plus" plain @click="create">新建订单</el-button> -->
                    <el-button type="primary" @click="downloadwithdrawa" plain><i class="iconfont icon-excel e-font-14 e-m-r-5"></i>导出Excel</el-button>
                    <!-- <el-button type="primary" icon="el-icon-map-location" plain @click="toMap">服务中订单地图</el-button> -->
                </div>
                <el-form :inline="true" class="demo-form-inline e-m-l-80 e-flex-1 text-right">
                    <el-form-item label="">
                        <div class="flex align-items-center">
                            <div class="e-flex-1">
                                <el-input placeholder="关键词搜索" prefix-icon="el-icon-search" v-model="key" clearable
                                    @change="getList"></el-input>
                            </div>
                            <!-- <el-checkbox v-model="firstOrder" @input="getList" class="e-m-l-15">是否首单</el-checkbox> -->
                        </div>
                    </el-form-item>
                    <!-- <el-form-item>
                        <span class="other-search-show" :class="isActive?'is-active':''" @click="isActive = !isActive">
                            {{isActive?'收起筛选':'更多筛选'}}<i class="el-icon-arrow-down el-icon--right"></i>
                        </span>
                    </el-form-item> -->
                    <el-form-item class="e-m-r-0">
                        <el-button type="primary" @click="getList(true)">查询</el-button>
                    </el-form-item>
                </el-form>
            </div>
            <!-- 更多筛选条件 -->
            <div class="other-search-form" :class="isActive ? 'is-active' : ''" v-if="insidePage == false">
                <el-form label-position="left" :inline="true" size="small">
                    <div class="flex align-items-center">
                        <!-- 时间筛选 -->
                        <timeChangeList v-model="timeType" @input="getList" @change="changeTime"></timeChangeList>
                    </div>
                    <div class="flex align-items-center">
                        <div class="e-flex-1" v-if="storeId == 0">
                            <el-form-item label="站点筛选">
                                <storeList v-model="innerStoreId" @change="selectStore"></storeList>
                            </el-form-item>
                        </div>
                        <div class="e-flex-1">
                            <el-form-item label="店员">
                                <userList v-model="staffId" @change="selectStaff"></userList>
                            </el-form-item>
                        </div>
                        <div class="e-flex-1">
                            <el-form-item label="订单地区">
                                <cityList v-model="cityid" @change="selectCity"></cityList>
                            </el-form-item>
                            <!-- <el-form-item>
                                <el-checkbox v-model="includeNextCity" @input="getList" class="e-m-l-30">是否包含下级地区</el-checkbox>
                            </el-form-item> -->
                        </div>
                    </div>
                    <div class="flex align-items-center">
                        <div class="e-flex-1">
                            <el-form-item label="结算方式">
                                <el-select v-model="payway" placeholder="选择结算方式" @change="getList(true)" clearable>
                                    <el-option label="微信支付" value="1"></el-option>
                                    <el-option label="现金支付" value="2"></el-option>
                                </el-select>
                            </el-form-item>
                        </div>
                        <div class="e-flex-1" v-if="enterpriseId == null">
                            <el-form-item label="所属客户组">
                                <enterpriseList v-model="listEnterpriseId" @change="selectEnterprise"></enterpriseList>
                            </el-form-item>
                        </div>
                        <div class="e-flex-1">
                            <el-form-item label="所属加盟商" v-if="franchiseId == null">
                                <franchiseList v-model="listFranchiseId" @change="selectFranchise"></franchiseList>
                            </el-form-item>
                        </div>
                    </div>
                </el-form>
            </div>
        </div>

        <!-- 选择订单状态 -->
        <div class="type-state e-m-b-30" v-if="insidePage == false">
            <span v-for="(item, index) in statusArr" :key="index" :class="{ 'on': manageState == item.value }"
                @click="getManageState(item.value)">
                <el-badge :value="item.count" class="item" :max="99" :hidden="item.value < 5 ? false : true">
                    {{ item.name }}
                </el-badge>
            </span>
        </div>

        <!-- 自定义表格 -->
        <custom-table storage-key="order-user-list" :table-data="tableData" :columns="tableColumns"
            :actions="tableActions" :total="total" :page-index="pageIndex" :page-size="pageSize"
            @page-change="handlePagination" @action-click="handleTableAction" :show-summary="true"
            :summary-method="getSummaries">
            <!-- 自定义地址列 -->
            <template #number="scope">
                <span>{{ scope.row.number }}</span>
                <el-tag size="mini" v-if="scope.row.firstorder">首</el-tag>
            </template>
            <!-- 自定义下单用户 -->
            <template #username="scope">
                <!-- <span v-if="scope.row.user">{{ scope.row.user.name }}</span> -->
                <!-- <span v-if="scope.row.enterprise"><el-tag size="mini">企</el-tag>{{ scope.row.enterprise.name }}({{scope.row.enterprise.department }})</span> -->

                <span v-if="scope.row.user"><el-button type="text" @click="userViews(scope.row.user)">{{ scope.row.user.name }}({{ scope.row.user.mobile }})</el-button></span>
                <span v-if="scope.row.enterprise"><el-button type="text" @click="userEnterpriseViews(scope.row.enterprise)"><el-tag size="mini">企</el-tag>{{ scope.row.enterprise.name }}({{scope.row.enterprise.department }})</el-button></span>
            </template>
            <!-- 自定义详细地址 -->
            <template #address="scope">
                <el-link type="primary"
                    @click="checkMap(scope.row.address.address, scope.row.address.lat, scope.row.address.lng)">{{ scope.row.address.address }}</el-link>
            </template>
            <!-- 自定义管理状态 -->
            <template #state="scope">
                <span class="color-success" v-if="scope.row.managestate == '已回收' || scope.row.managestate == '已入库'">{{
                        scope.row.managestate
                    }}</span>
                <span class="color-warning"
                    v-else-if="scope.row.managestate == '待接单' || scope.row.managestate == '已接单' || scope.row.managestate == '待上门' || scope.row.managestate == '待上门' || scope.row.managestate == '待付款'">{{
                        scope.row.managestate
                    }}</span>
                <span class="color-danger" v-else>{{ scope.row.managestate }}</span>
            </template>
        </custom-table>

        <!-- 取消参考信息 -->
        <el-dialog title="取消订单" :visible.sync="showcancelInfo" width="60%">
            <el-form ref="form" :model="cancelForm" label-width="auto">
                <div class="flex">
                    <div class="e-flex-1">
                        <el-form-item label="追回金额方式">
                            <el-radio-group v-model="cancelForm.way">
                                <el-radio :label="1">账户扣除</el-radio>
                                <el-radio :label="2">线下</el-radio>
                            </el-radio-group>
                        </el-form-item>
                    </div>
                </div>
                <div class="e-p-b-10">
                    <div class="tips">说明：</div>
                    <div class="tips">1.账户扣除会扣除客户账户上的余额，客户账户余额不足（已被提现）时无法扣除；该收货订单是现金收货时无法扣除。</div>
                    <div class="tips">2.线下取消仅会撤销该订单，金额不会追回。</div>
                </div>
                <div class="flex">
                    <div class="e-flex-1">
                        <el-input type="textarea" :rows="5" placeholder="请输入取消订单的理由" v-model="cancelForm.reason" maxlength="200"></el-input>
                    </div>
                </div>
            </el-form>
            
            <span slot="footer" class="dialog-footer">
                <el-button @click="showcancelInfo = false">取消</el-button>
                <el-button type="primary" @click="confirmCancelOrder">确定</el-button>
            </span>
        </el-dialog>
        <!-- 查看详细地址 -->
        <el-dialog title="查看详细地址" :visible.sync="dialogVisible" width="1200px" z-index="99">
            <div id="container" class="e-m-t-10" style="width:100%;height: 600px;"></div>
        </el-dialog>
        <!-- 详情页面弹窗(线下入库订单详情) -->
        <el-drawer :visible.sync="fitViewShow.show" direction="rtl" size="80%" :with-header="false" :append-to-body="true">
            <fitOrderViews v-if="fitViewShow.show" :id="fitViewShow.id" @goBack="fitViewShow.show = false">
            </fitOrderViews>
        </el-drawer>
        <!-- 用户详情页面弹窗 -->
        <el-drawer title="" :visible.sync="userView.show" direction="rtl" size="80%" :with-header="false" :append-to-body="true">
            <userView v-if="userView.show" :id="userView.id" @goBack="userView.show = false"></userView>
        </el-drawer>
        <!-- 单位详情页面弹窗 -->
        <el-drawer title="" :visible.sync="enterpriseDetails.show" direction="rtl" size="80%" :with-header="false" :append-to-body="true">
            <enterpriseView v-if="enterpriseDetails.show" :id="enterpriseDetails.id" @goBack="enterpriseDetails.show = false"></enterpriseView>
        </el-drawer>
    </div>
</template>

<script>
import userOrderViews from './userOrderViews.vue'
import fitOrderViews from './fitOrderViews.vue'
import timeChangeList from '@/components/form-select-type/timeChangeList.vue'
import userList from '@/components/form-select-type/userList.vue'
import storeList from '@/components/form-select-type/storeList.vue'
import cityList from '@/components/form-select-type/cityList.vue'
import enterpriseList from '@/components/form-select-type/enterpriseList.vue'
import franchiseList from '@/components/form-select-type/franchiseList.vue'
import userView from '@/pages/user/components/views.vue'
import enterpriseView from '@/components/enterprise-list/views.vue'
export default {
    components: {
        userOrderViews,
        fitOrderViews,
        timeChangeList,
        userList,
        storeList,
        cityList,
        enterpriseList,
        franchiseList,
        userView,
        enterpriseView
    },
    props: {
        franchiseId: {
            type: [Number, String],
            default: null
        },
        enterpriseId: {
            type: [Number, String],
            default: null
        },
        insidePage:{
            type: Boolean,
            default: false
        },
        userId: {
            type: [Number, String],
            default: 0
        },
        storeId: {
            type: [Number, String],
            default: 0
        },
    },
    data() {
        return {
            // 单位详情页面弹窗
            enterpriseDetails: {
                id: 0,
                show: false
            },
            // 用户详情页面弹窗
            userView: {
                id: 0,
                show: false
            },
            // 回收订单（线上）显示
            viewShow: {
                id: 0,
                show: false //详情页面弹窗
            },
            // 回收订单（下线）显示
            fitViewShow: {
                id: 0,
                show: false
            },
            payway: null,
            // 时间类型
            timeType: 0, //筛选时间类别：0全部，1今日，2昨日，3本月，4上月，5本季度，6上季度，7本年，9自定义时间段
            startDate: '', //开始时间
            endDate: '', //结束时间
            dateByType: 3,//时间按什么类型搜索,timeType>0时有效，0.创建时间，1.预约上门时间，2.小哥上门时间,3.完成时间
            dateByTypeList: [
                {
                    value: 0,
                    label: '创建时间'
                },
                // {
                //     value: 1,
                //     label: '预约上门时间'
                // },
                // {
                //     value: 2,
                //     label: '小哥上门时间'
                // },
                {
                    value: 3,
                    label: '完成时间'
                },
            ],
            startDate: "",//下单初始
            endDate: "",//下单结束
            innerStoreId: null,//站点id
            // useList: [],
            userid: 0,
            cityid: 0, //城市id
            includeNextCity: true,//是否包含下级地区
            listEnterpriseId: null,//客户组id
            userType: 2,//用户订单类型：0全部，1客户组订单，2用户订单\n\n注1. 用户或客户组登录时,0无效默认为2
            staffId: null, //负责小哥id
            listFranchiseId: null,
            orderType: 2,
            // firstOrder: false,//是否首单
            options: [
                // {
                //     value: null,
                //     label: '全部'
                // },
                {
                    value: 1,
                    label: '上门订单'
                },
                {
                    value: 2,
                    label: '站点订单'
                }
            ],
            value: '',
            statusArr: [
                {
                    name: '全部',
                    value: null
                },
                {
                    name: '已入库',
                    value: 8
                },
                {
                    name: '已取消',
                    value: 5
                },
            ],
            manageState: null,
            nowid: 0,
            textarea: "",
            showcancelInfo: false,
            cancelForm: {
                id: 0,
                reason: "",
                way: 0, //追回金额方式 (已完成订单必选),1.账户扣除 （现金支付时无效）2.线下
                state: ""
            },
            // cancelInfo: {
            //     id: 0,
            //     number: '',
            //     amount: 0,
            //     payway: '',
            //     accountnumber: '',
            //     promotionusertype: '',
            //     promotionusernumber: '',
            //     promotionuserid: 0,
            //     promotioncommission: 0
            // },
            loading: true,
            key: '',
            pageIndex: 1,
            pageSize: 10,
            total: 0,
            tableData: [],
            tableColumns: [
                {
                    prop: 'number',
                    label: '订单ID',
                    width: 200,
                    slotName: 'number'
                },
                {
                    prop: 'store',
                    label: '站点',
                    width: 'auto',
                    formatter: (row) => {
                        if (row.store) {
                            return row.store.name
                        } else {
                            return '--'
                        }
                    }
                },
                {
                    prop: 'username',
                    label: '下单用户',
                    slotName: 'username',
                    width: 'auto'
                    // formatter: row => `${row.name} (${row.mobile})`
                },
                {
                    prop: 'usermobile',
                    label: '联系电话',
                    width: 120,
                    // slotName: 'usermobile',
                    formatter: row => `${row.user ? row.user.mobile : '--'}`
                },
                // { 
                //   prop: 'enterprise', 
                //   label: '客户组名称',
                //   width: 'auto',
                //   formatter: (row)=>{
                //     if(row.enterprise){
                //       return row.enterprise.name
                //     }else{
                //       return '--'
                //     }
                //   }
                // },
                // { 
                //   prop: 'citynames', 
                //   label: '所属地区', 
                //   width: 120,
                // },
                // {
                //     prop: 'address',
                //     label: '详细地址',
                //     width: 120,
                //     slotName: 'address',
                // },
                {
                    prop: 'weight',
                    label: '重量(KG)',
                    width: 120,
                },
                {
                    prop: 'quantity',
                    label: '件数(件)',
                    width: 120,
                },
                {
                    prop: 'amount',
                    label: '回收金额（元）',
                    width: 120,
                    formatter: row => `${row.amount || '--'}`
                },
                // {
                //     prop: 'terminal',
                //     label: '订单来源',
                //     width: 100,
                //     formatter: function (row) {
                //         switch (row.terminal) {
                //             case 'OMS':
                //                 return '运营后台'
                //             case 'AIO':
                //                 return '站点端'
                //             case 'APP':
                //                 return '手机端'
                //             case 'WX':
                //                 return '微信端'
                //             case 'PC':
                //                 return '电脑端'
                //             default:
                //                 return '--'
                //         }
                //     }
                // },
                {
                    prop: 'payway',
                    label: '结算方式',
                    width: 100,
                },
                {
                    prop: 'createddatetime',
                    label: '订单时间',
                    width: 180,
                },
                {
                    prop: 'staff',
                    label: '店员',
                    width: 120,
                    formatter: row => `${row.staff?.name || '未分配'}`
                },
                {
                    prop: 'remarks',
                    label: '备注',
                    width: 180,
                    formatter: row => `${row.remarks || '--'}`
                },
                {
                    prop: 'state',
                    label: '管理状态',
                    width: 120,
                    slotName: 'state',
                },
            ],
            tableActions: [
                {
                    name: 'view',
                    label: '查看',
                    // visible: row => row.status !== 'deleted'
                },
                {
                    name: 'distribution-1',
                    label: '派单',
                    visible: row => row.managestate == 1
                },
                {
                    name: 'distribution-2',
                    label: '更换小哥',
                    visible: row => row.managestate == 2 || row.managestate == 3 || row.managestate == 4
                },
                {
                    name: 'cancel',
                    label: '取消订单',
                    visible: row => row.managestate != 5
                }
            ],
            // 小哥派单
            form: {
                cityid: null,
                key: ''
            },
            distributionShow: false,
            distributionForm: {
                orderId: 0,
                staffId: 0
            },
            distributionList: [],
            changeBrother: false,
            // 查看用户地图
            address: '',
            lat: 0,
            lng: 0,
            dialogVisible: false,
            isActive: true, //控制更多筛选显示
            param: {}
        }
    },
    watch: {
        manageState(value) {
            this.getList()
        },
        // tablefield:{
        //   deep:true,//true为进行深度监听,false为不进行深度监听
        //   handler(newVal){
        //     localStorage.setItem('order-user-list', JSON.stringify(newVal));
        //   }
        // }
    },
    mounted() {
        for (let k in this.$route.query) {
            if (this.$route.query[k]) {
                if (k == 'pageIndex' || k == 'pageSize') {
                    this[k] = parseInt(this.$route.query[k])
                } else if (k == 'firstOrder') {
                    this[k] = Boolean(this.$route.query[k])
                } else if (k == 'startDate' || k == 'endDate') {
                    this[k] = this.$route.query[k]
                    // this.value1 = [this.$route.query['startDate'], this.$route.query['endDate']]
                    // this.timeType = 4
                } else {
                    this[k] = this.$route.query[k]
                }

                if (k == 'orderType' || k == 'startDate' || k == 'endDate' || k == 'timeType' || k == 'firstOrder' || k == 'staffId') {
                    this.isActive = true
                }
            }
        }
        if(this.listEnterpriseId > 0 || this.enterpriseId > 0){
            this.userType = 1
        }else{
            this.userType = 2
        }
        this.getList()


        // /*
        //   自定义列表字段显示，需配合watch侦听tablefield参数
        // */
        // if(localStorage.getItem('order-user-list')){
        //   this.tablefield = JSON.parse(localStorage.getItem('order-user-list'));
        // }
    },
    methods: {
        // 查看用户详情
        userViews(item){
            this.userView.id = item.id
            this.userView.show = true
        },
        // 查看单位详情
        userEnterpriseViews(item){
            this.enterpriseDetails.id = item.id
            this.enterpriseDetails.show = true
        },
        // 翻页操作处理
        handlePagination({ pageIndex, pageSize }) {
            this.pageIndex = pageIndex
            this.pageSize = pageSize
            this.getList(false) // 获取新数据
        },
        // 操作按钮点击事件
        handleTableAction({ action, row, event }) {
            switch (action) {
                case 'view':
                    this.goViewShow(event, row)
                    break
                case 'cancel':
                    this.cancelOrder(row)
                    break
            }
        },
        // 获取列表数据统计
        getSummaries(param) {
            const { columns, data } = param;
            const sums = [];
            columns.forEach((column, index) => {
                if (index === 0) {
                    sums[index] = '合计';
                    return;
                }
                const values = data.map(item => Number(item[column.property]));
                if (!values.every(value => isNaN(value))) {
                    sums[index] = values.reduce((prev, curr) => {
                        const value = Number(curr);
                        if (!isNaN(value)) {
                            return prev + curr;
                        } else {
                            return prev;
                        }
                    }, 0);
                    sums[index] += '';
                } else {
                    sums[index] = '';
                }

                if (column.label == '回收金额（元）') {
                    sums[index] = Number(sums[index]).toFixed(2)
                }
                else if (column.label == '重量(KG)') {
                    sums[index] = Number(sums[index]).toFixed(2)
                } else {
                    sums[index] = ''
                }
            });

            return sums;
        },
        // 选择时间
        changeTime(e) {
            console.log(e)
            this.startDate = e['startDate']
            this.endDate = e['endDate']
            this.timeType = e['timeType']
            this.getList()
        },
        // 选择订单管理状态
        getManageState(val) {
            this.pageIndex = 1
            this.manageState = val
        },
        // 选择地区
        selectCity(value){
            this.cityid = value,
            this.getList(true)
        },
        // 选择站点
        selectStore(value){
            this.innerStoreId = value,
            this.getList(true)
        },
        // 选择小哥
        selectStaff(value){
            this.staffId = value,
            this.getList(true)
        },
        // 选择客户组
        selectEnterprise(value){
            this.listEnterpriseId = value
            if(this.listEnterpriseId > 0){
                this.userType = 1
            }else{
                this.userType = 2
            }
            this.getList(true)
        },
        // 选择加盟商
        selectFranchise(value){
            this.listFranchiseId = value,
            this.getList(true)
        },
        toMap() {
            this.$router.push({
                path: '/order/user/map'
            })
        },
        // getuselist() {
        //   this.$axios.post('/Select/UserList', {
        //     "pageIndex": 1,
        //     "pageSize": 20,
        //     "offset": 0,
        //     "key": this.key,
        //   }).then((res) => {
        //     console.log(res)
        //     this.useList = res.rows
        //     this.useList.unshift({
        //       name: '全部',
        //       id: 0
        //     })
        //   })
        // },
        create() {
            this.$router.push({
                path: '/order/user/create'
            })
        },

        cancelOrder(row) {
            this.cancelForm.id = row.id;
            this.cancelForm.reason = ''
            this.cancelForm.way = 0
            this.cancelForm.state = row.state
            this.showcancelInfo = true;
        },
        // 确认取消订单
        confirmCancelOrder() {
            this.$axios.post('/User/Order/FITCancel', {
                id: this.cancelForm.id,
                reason: this.cancelForm.reason,
                way: this.cancelForm.way
            }).then((res) => {
                this.$message({
                    type: 'success',
                    message: res.msg
                });
                this.showcancelInfo = false;
                this.textarea = "";
                this.getList()
            })
        },
        getList(renew = true) {
            if (renew == true) {
                this.pageIndex = 1
            }
            this.tableData = []
            this.loading = true
            this.param = {
                "orderType": 2,
                "pageIndex": this.pageIndex,
                "pageSize": this.pageSize,
                "key": this.key,
                "manageState": this.manageState,
                "timeType": this.timeType,
                "startDate": this.startDate,
                "endDate": this.endDate,
                "userid": this.userid || 0,
                "cityid": this.cityid || 0,
                "cityByType": 0,
                // "firstOrder": this.firstOrder,
                "staffId": this.staffId || 0,
                "storeId": this.storeId || this.innerStoreId || 0,
                "dateByType": this.dateByType,
                "franchiseId": this.franchiseId || this.listFranchiseId || 0,
                "includeNextCity": this.includeNextCity,
                "enterpriseId": this.enterpriseId|| this.listEnterpriseId || 0,
                "includeDepartment": true,
                "userType": this.userType,
                "userId": this.userId,
                "payway": this.payway
            }
            return this.$axios.post('/User/Order/List', this.param).then((res) => {
                this.loading = false

                this.statusArr = []
                res.managestate.forEach((item)=>{
                    if(item.name == '已入库' || item.name == '已取消'){
                        this.statusArr.push(item)
                    }
                })
                this.statusArr.sort((a, b) => b.value - a.value)
                this.statusArr.unshift({
                    name: '全部',
                    value: null
                })
                this.tableData = res.rows;
                this.total = res.total;
            }).catch((err) => {
                this.loading = false
            })
        },
        downloadwithdrawa() {
            this.$axios.post('/User/Order/Download', {
                "request": {
                    "orderType": 2,
                    "pageIndex": this.pageIndex,
                    "pageSize": this.pageSize,
                    "key": this.key,
                    "manageState": this.manageState,
                    "timeType": this.timeType,
                    "startDate": this.startDate,
                    "endDate": this.endDate,
                    "userid": this.userid || 0,
                    "cityid": this.cityid || 0,
                    "cityByType": 0,
                    // "firstOrder": this.firstOrder,
                    // "staffId": this.staffId || 0,
                    "storeId": this.storeId || this.innerStoreId || 0,
                    "dateByType": this.dateByType,
                    "franchiseId": this.franchiseId || this.listFranchiseId || 0,
                    "includeNextCity": this.includeNextCity,
                    "enterpriseId": this.enterpriseId|| this.listEnterpriseId || 0,
                    "includeDepartment": true,
                    "userType": this.userType,
                    "userId": this.userId,
                    "payway": this.payway
                },
                "fields": [
                    {
                        "e": "Number",
                        "c": "订单编号"
                    },
                    {
                        "e": "Terminal",
                        "c": "订单来源"
                    },
                    {
                        "e": "Enterprise.Name||User.Name",
                        "c": "下单用户"
                    },
                    // {
                    //     "e": "Enterprise.Name",
                    //     "c": "下单企业"
                    // },
                    {
                        "e": "Address.CityNames",
                        "c": "所属地区"
                    },
                    {
                        "e": "Address.address",
                        "c": "详细地址"
                    },
                    {
                        "e": "User.Mobile",
                        "c": "联系电话"
                    },
                    {
                        "e": "CreatedDateTime",
                        "c": "订单时间"
                    },
                    {
                        "e": "weight",
                        "c": "重量（KG）"
                    },
                    {
                        "e": "Quantity",
                        "c": "件数（件）"
                    },
                    {
                        "e": "Amount",
                        "c": "金额"
                    },
                    // {
                    //     "e": "brother.name",
                    //     "c": "派送小哥"
                    // },
                    {
                        "e": "completiontime",
                        "c": "完成时间"
                    },
                    {
                        "e": "ManageState",
                        "c": "管理状态"
                    },
                ]
            }, {
                responseType: 'blob'
            }).then(res => {
                console.log(res)
                let content = res;
                let fileName = '站点订单.xls'
                this.utils.saveAndExport(content, fileName)
            })
        },
        goView(row) {
            let param = []
            for (let k in this.param) {
                if (this.param[k]) {
                    param.push(`${k}=${this.param[k]}`)
                }
            }
            this.$router.push(`/order/user/list?${param.join('&')}`)
            return '/order/brother/fitViews?id=' + row.id
        },
        rowClick(row) {
            // if (row.terminal == 'AIO') {
            //   this.fitViewShow.id = row.id
            //   this.fitViewShow.show = true
            // } else {
            //   this.viewShow.id = row.id
            //   this.viewShow.show = true
            // }
        },
        goViewShow(event, row) {
            if (event.ctrlKey) {
                console.log('Ctrl + 左键点击');
                // 这里可以执行你需要的操作
                let param = []
                for (let k in this.param) {
                    if (this.param[k]) {
                        param.push(`${k}=${this.param[k]}`)
                    }
                }
                this.$router.push(`/order/user/list?${param.join('&')}`)
                    window.open('/order/brother/fitViews?id=' + row.id, '_blank');
            } else {
                console.log('普通点击');
                // return '/order/brother/fitViews?id=' + row.id
                this.fitViewShow.id = row.id
                this.fitViewShow.show = true
            }
        },
        // 百度地图初始化
        initMap() {
            let that = this
            let marker = []
            this.$AMapLoader.load({
                key: this.AMapSetting.key,             // 申请好的Web端开发者Key，首次调用 load 时必填
                version: this.AMapSetting.version,      // 指定要加载的 JSAPI 的版本，缺省时默认为 1.4.15
                plugins: ['AMap.PlaceSearch'],       // 需要使用的的插件列表，如比例尺'AMap.Scale'等
            }).then((AMap) => {
                var map = new AMap.Map("container", {  //设置地图容器id
                    resizeEnable: true,
                    center: [this.lng, this.lat], //初始化地图中心点位置
                });
                var keywords = this.address;

                // 移除已创建的 marker
                map.remove(marker);
                marker = new AMap.Marker({
                    position: new AMap.LngLat(that.lng, that.lat),   // 经纬度对象，也可以是经纬度构成的一维数组[116.39, 39.9]
                    title: keywords
                });

                // 将创建的点标记添加到已有的地图实例：
                map.add(marker);
                map.setFitView();

            }).catch(e => {
                console.log(e);
            })
        },
        // 查看用户地址地图
        checkMap(address, lat, lng) {
            this.dialogVisible = true
            this.address = address
            this.lat = lat
            this.lng = lng
            this.initMap()
        },
    }
}
</script>

<style lang="scss" scoped>

</style>